package com.bigdata.management.controller;

import com.bigdata.management.bean.Customer;
import com.bigdata.management.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ConsumerController {

    @Autowired
    private CustomerService customerService;


    @RequestMapping("/hello")
    public String helloword(@RequestParam("name") String name,@RequestParam("age") int age) {
        return "hello "+name+" "+age;
    }

    @RequestMapping("/hello2/{name}/{age}")
    public String hello(@PathVariable("name") String name,@PathVariable("age") int age) {
        return "hello "+name+" "+age;
    }

    @PostMapping("/hello3")
    public String hello3(@RequestBody Customer customer) {
        System.out.println(customer);
        return "hello "+customer.getName()+" "+customer.getAge();
    }

    @RequestMapping(path = "/hello4",method = RequestMethod.POST)
    public Customer hello4(@RequestParam String name) {
        System.out.println(name);
        Customer customer = customerService.getCustomerByName(name);
        return customer;
    }

    @RequestMapping(path = "/hello5",method = RequestMethod.GET)
    public List<Customer> hello5() {

        List<Customer> customers = customerService.getAllCustomer();
        return customers;
    }

    @RequestMapping(path = "/hello6",method = RequestMethod.GET)
    public void hello6(@RequestParam("name") String name,@RequestParam("age") int age) {

        customerService.insertCustomer(new Customer(name,age));
    }

    @RequestMapping(path = "/hello7",method = RequestMethod.GET)
    public void hello7(@RequestParam("name") String name,@RequestParam("age") int age) {

        customerService.updateCustomer(new Customer(name,age));
    }


}
